import { createRouter, createWebHistory } from 'vue-router'
//导入跳转路由组件
import AdminLogin from '../components/AdminLogin.vue'
import AdminPage from '../components/AdminPage.vue'
import AdminPageClassesStudent from '../components/AdminPageClassesStudent.vue'
import AdminPageClasses from '../components/AdminPageClasses.vue'

import AdminPageClassesSubject from '../components/AdminPageClassesSubject.vue'
import AdminPageCourse from '../components/AdminPageCourse.vue'
import AdminPageExamination from '../components/AdminPageExamination.vue'
import AdminPageRole from '../components/AdminPageRole.vue'
import AdminPageScore from '../components/AdminPageScore.vue'
import AdminPageStudentRole from '../components/AdminPageStudentRole.vue'
import AdminPageSubject from '../components/AdminPageSubject.vue'
import AdminPageTeacherRole from '../components/AdminPageTeacherRole.vue'
import AdminTeacherClasses from '../components/AdminTeacherClasses.vue'
import AdminStudentExamination from '../components/AdminStudentExamination.vue'
//Admin端
import { adminStateStore } from '../store/AdminInfo.js'



//路由编写
const router = createRouter({
    history: createWebHistory(),
    routes: [
        //初始页面路由
        {
            path: "/",
            components: {
                AdminRouter: AdminLogin
            }
        },
        {
            path: "/login",
            components: {
                AdminRouter: AdminLogin
            }
        },
        {
            path: "/page",
            components: {
                AdminRouter: AdminPage
            },
            children: [
                //班级管理
                {
                    path: "/page/classes",
                    components: {
                        AdminPageRouter: AdminPageClasses
                    }
                },
                //班级学生管理
                {
                    path: "/page/classes/student",
                    components: {
                        AdminPageRouter: AdminPageClassesStudent
                    }
                },
                //班级课程管理
                {
                    path: "/page/classes/subject",
                    components: {
                        AdminPageRouter: AdminPageClassesSubject
                    }
                },
                //课程管理2 已废弃
                {
                    path: "/page/classes/course",
                    components: {
                        AdminPageRouter: AdminPageCourse
                    }
                },
                //考试管理
                {
                    path: "/page/examination",
                    components: {
                        AdminPageRouter: AdminPageExamination
                    }
                },
                //管理员角色管理界面
                {
                    path: "/page/admin/role",
                    components: {
                        AdminPageRouter: AdminPageRole
                    }
                },
                //分数管理界面
                {
                    path: "/page/score",
                    components: {
                        AdminPageRouter: AdminPageScore
                    }
                },
                //学生管理界面
                {
                    path: "/page/student/role",
                    components: {
                        AdminPageRouter: AdminPageStudentRole
                    }
                },
                //课程管理
                {
                    path: "/page/subject",
                    components: {
                        AdminPageRouter: AdminPageSubject
                    }
                },
                //教师管理
                {
                    path: "/page/teacher/role",
                    components: {
                        AdminPageRouter: AdminPageTeacherRole
                    }
                },
                //教师课程管理
                {
                    path: "/page/classes/teacher",
                    components: {
                        AdminPageRouter: AdminTeacherClasses
                    }
                },
                //学生考试管理
                {
                    path: "/page/examination/student",
                    components: {
                        AdminPageRouter: AdminStudentExamination
                    }
                },
            ]
        }
    ]
})
//路由控制页面的跳转
router.beforeEach(
    (to, from, next) => {
        const admin = adminStateStore();
        //路由跳转
        if (to.path == "/login" || to.path=="/") {
            //登录页面放行
            next();
        }
        if (to.path == "/page" || to.path == "/page/classes" || to.path == "/page/classes/student" || to.path == "/page/classes/subject" || to.path == "/page/examination" || to.path == "/page/admin/role" || to.path == "/page/score" || to.path == "/page/student/role" || to.path == "/page/subject" || to.path == "/page/teacher/role" || to.path == "/page/classes/teacher" || to.path == "/page/examination/student" ) {
            if (admin.getterAdminadminLoginState == 1) {
                next()
            }
        }


    }
)

export default router;//路由